package _17_剑指Offer;

public class _21_剑指Offer调整数组顺序使奇数位于偶数前面 {

    public int[] exchange(int[] nums) {
        int left = 0;
        int right = nums.length - 1;

        while (left < right) {

            while (left < right && (nums[left] & 1) == 1) left++;

            while (left < right && (nums[right] & 1) == 0) right--;

            // 交换元素至
            int temp = nums[left];
            nums[left] = nums[right];
            nums[right] = temp;
        }
        return nums;
    }

}
